home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_GDATE.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  7KB  |  156 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gdate - get date from window with gross validation 
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. ************
  17. * wn_gdate *
  18. ************
  19. */
  20.  
  21. /*
  22. ** wn_gdate(fun,frm,fld,wn,row,col,prmpt,atrib,fill,month,day,year,ubuff,hlpmsg,errmsg)
  23. **
  24. **    int        fun - fucntion code (SET || XEQ)
  25. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  26. **    int        fld - field # in form (actual || NULL)
  27. **    (WINDOWPTR) wn - window pointer
  28. **    int        row - row in window where data input begins
  29. **    int        col - col in window where data input begins
  30. **    (char *) prmpt - field promt (call with NSTR for none)
  31. **    unsigned atrib - field (not prompt) atributes 
  32. **    char      fill - field fill character
  33. **    (int *)  month - pointer to int for month (1-12)
  34. **    (int *)    day - pointer to int for day (1-31)
  35. **    (int *)   year - pointer to int for year (0-99)
  36. **    (char *) ubuff - pointer to char array of 10 bytes for editing 
  37. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  38. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  39. **
  40. ** RETURNS:
  41. **
  42. **    MONTH, DAY, and YEAR via pointers.
  43. **
  44. **    NULL if error, else the non zero value returned from wn_input.
  45. **
  46. ** NOTES:
  47. **
  48. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  49. **          execution.  When called with SET, valid arguements for both
  50. **          "frm" and "fld" must be specfied.  frm is the field pointer
  51. **          returned from frmopn(), and fld is the field sequence number
  52. **          in the form for this field.  When called with XEQ frm must
  53. **          be NFRM and fld must NULL.
  54. **
  55. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  56. **          data as it is entered.  Typical value is the length
  57. **          of the mask + 2 bytes (strlen(mask)+2).
  58. **
  59. **          On entry, the first byte of ubuff should be 
  60. **          a null, otherwise wn_input assumes there is valid
  61. **          data there and will enter edit mode.  This can be 
  62. **          handy if there is a need for prefilled but editable
  63. **          fields.  In actual pratice, wn_input uses this
  64. **          buffer for both initial character data entry and
  65. **          subsequent editing.
  66. **
  67. **          On return, ubuff contains the actual data entered in
  68. **          character format with fill and mask characters as
  69. **          spaces (e.g. "12 12 88").
  70. **
  71. **  Only basic reasonability checks are made.  Therefore, dates like
  72. **  02/31/88 can be returned.
  73. **
  74. **  Calls wn_input to perform data entry.
  75. **
  76. **  Data must satisfy validation checks for function to return.
  77. */
  78.  
  79. wn_gdate(fun,frm,fld,wn,row,col,prmpt,atrib,fill,month,day,year,ubuff,hlpmsg,errmsg)
  80. int fun;                                /* SET or XEQ */
  81. WIFORM frm;                             /* form pointer or NFRM */
  82. int fld;                                /* field number or NULL */
  83. WINDOWPTR wn;                           /* window to use */
  84. int row, col;                           /* position of input field */
  85. char *prmpt;                            /* prompt string */
  86. unsigned atrib;                         /* data entry atribute */
  87. char fill;                              /* fill char */
  88. int *month, *day, *year;                /* ints of month,day,year */
  89. char *ubuff;                            /* returns "mm/dd/yy" */
  90. char *hlpmsg,*errmsg;                   /* help and error messages */
  91. {
  92. int m, d, y;                            /* month day & year */
  93. char mbuf[10];                          /* local buffer */
  94. char *p;                                /* scratch */
  95. unsigned int r;                         /* sscanf return value */
  96. int rv;                                 /* return value */
  97. int eflg;                               /* error flag */
  98.  
  99.   if(fun != SET && fun != XEQ)          /* saftey check */
  100.     return(NULL);
  101.  
  102.   if(fun == SET) {                      /* set up */
  103.     if(frm[fld]->pself != (char *)frm[fld])
  104.       wns_ierr("wn_gdate");             /* die if memory is mangled */
  105.     frm[fld]->wn = wn;                  /* set window */
  106.     frm[fld]->row = row;                /* set row */
  107.     frm[fld]->col = col;                /* set col */
  108.     frm[fld]->prmpt = prmpt;            /* set prompt */
  109.     frm[fld]->atrib = atrib;            /* set attribute */
  110.     frm[fld]->fill = fill;              /* set fill character */
  111.     frm[fld]->fcode = GDATE;            /* function code */
  112.     frm[fld]->v1.vip = month;           /* &month */
  113.     frm[fld]->v2.vip = day;             /* &day */
  114.     frm[fld]->v3.vip = year;            /* &year */
  115.     frm[fld]->v4.vcp = ubuff;           /* &ubuff */
  116.     frm[fld]->v5.vcp = hlpmsg;          /* &hlpmsg */
  117.     frm[fld]->v6.vcp = errmsg;          /* &errmsg */
  118.     return(TRUE);
  119.   }
  120.  
  121. begin:
  122.   if(!(rv=wn_input(wn,row,col,prmpt,"##/##/##",fill,atrib,ubuff,hlpmsg))) {
  123.     *ubuff = NUL;                       /* load ubuff with a bad date */
  124.     return(NULL);                       /* indicate error */
  125.   }
  126.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  127.   if(wns_escape) return(rv);            /* escape pressed ?? */
  128.   strcpy(mbuf,ubuff);                   /* load my buffer */
  129.   p = mbuf;                             /* set pointer */
  130.   while (*p) {                          /* set up to pluck */
  131.     if(*p == '/')                       /* the slash */
  132.       *p = ' ';                         /* and stash a space */
  133.     p++;                                /* bump pointer */
  134.   }                                     /* continue till done */
  135.   r =  sscanf(mbuf, "%02d %02d %02d", &m, &d, &y);
  136.   if(r == EOF || r == 0) {              /* no data - set to zip */
  137.     *month = *day = *year = 0;          /* set to zip */
  138.     return(rv);                         /* and return */
  139.   }
  140.   eflg = FALSE;
  141.   if(r != 3) eflg = TRUE;               /* not enuf data */
  142.   if(m < 1 || m > 12) eflg = TRUE;      /* bad month */
  143.   if(d < 1 || d > 31) eflg = TRUE;      /* bad day */
  144.   if(y < 0 || y > 99) eflg = TRUE;      /* bad year */
  145.   if(eflg) {
  146.     wn_iemsg(errmsg);                   /* do error thing */
  147.     goto begin;                         /* and start over */
  148.   }
  149.   *month = m;                           /* load user month */
  150.   *day = d;                             /* and day */
  151.   *year = y;                            /* and year */
  152.   return(rv);                           /* all is well.. in gross sense */
  153. }
  154.  
  155. /* End */
  156.